package com.example.resource_station_backend.dao;


import com.example.resource_station_backend.model.dto.articles.ArticlesQueryRequest;
import com.example.resource_station_backend.model.entity.Articles;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @Author xinhao
 * @Description
 * @CreateTime 2025-02-24 18:36:17
 */
@Repository
public interface ArticlesRepository extends JpaRepository<Articles, Long> {
    // 获取文章列表(包含内容)
    List<Articles> findAll();
    // 按分类id获取资讯文章详细
    Optional<Articles> findByCategoryId(Long id);
    // 获取文章列表(去除内容和爬取时间)
    @Query("SELECT new com.example.resource_station_backend.model.dto.articles.ArticlesQueryRequest(a.id, a.title ,a.summary ,a.category.id ,a.cover ,a.author, a.published_at) FROM Articles a")
    List<ArticlesQueryRequest> findArticlesWithoutContent();
    // 按分类id获取资讯文章列表(去除内容和爬取时间)
    @Query("SELECT new com.example.resource_station_backend.model.dto.articles.ArticlesQueryRequest(a.id, a.title ,a.summary ,a.category.id ,a.cover ,a.author, a.published_at) FROM Articles a WHERE a.category.id = :id")
    List<ArticlesQueryRequest> findByCategoryIdWithoutContent(Long id);
}
